{extend name="index/index"/}

{block name="main"}

<div class="admin-biaogelist">

    <div class="listbiaoti am-cf">
        <ul class="am-icon-flag on"> {$title}</ul>

        <dl class="am-icon-home" style="float: right;"> 当前位置： 首页 > <a href="#">导航分类管理列表</a></dl>

        <dl>

            <a type="button" class="am-btn am-btn-danger am-round am-btn-xs am-icon-plus" href ="{:url('admin/classify/create')}" method="post">添加分类</a>

        </dl>


    </div>


    <form class="am-form am-g">
        <table width="100%" class="am-table am-table-bordered am-table-radius am-table-striped">
            <thead>
            <tr class="am-success">
                <th class="table-id">ID</th>
                <th class="col-md-3">分类名称</th>
                <th class="col-md-6">连接路径</th>
                <th width="163px" class="table-set">操作</th>
            </tr>
            </thead>
            <tbody>
            {volist name="data" id="v" mod="1"}
            {eq name="mod" value="0"}
            <tr>
                <td>{$v['id']}</td>
                <td>{:str_repeat('&nbsp',$v['count']*8).'|--'.$v['cate_name']}</td>
                <td>{$v['href_path']}</td>

                <td><div class="am-btn-toolbar">
                    <div class="am-btn-group am-btn-group-xs">

                        <a class="am-btn am-btn-default am-btn-xs am-text-secondary am-round" href="{:url('admin/classify/edit',['id'=>$v['id']])}"><span class="am-icon-pencil-square-o"></span></a>
                        <div data-id="{$v['id']}" class="am-btn am-btn-default am-btn-xs am-text-danger am-round btn-del"><span class="am-icon-trash-o"></span></div>
                    </div>
                </div></td>
            </tr>
            {/eq}
            {/volist}
            </tbody>
        </table>

    </form>






</div>
<script>
    $(function(){
        //触发用户的删除操作
        $('.btn-del').click(function(){
            var ac_id = $(this).attr('data-id');
            console.log('删除操作的id为:',ac_id);

            if(confirm('你确定要删除该分类名吗？')){
                var obj = $(this).parents('tr');
                console.log(obj);

                //调用ajax进行删除
                delAjax(ac_id,obj);
            }
        });

        //执行ajax删除
        function delAjax(id,obj){
            $.ajax({
                type : 'delete',      //delete 删除方式
                url : '/classify/'+id,
                dataType : 'json',
                success : function(data){
                    console.log(data);
                    if (data.status) {
                        alert(data.info);
                        // 将当前的节点删除掉
                        obj.remove();
                    } else {
                        alert(data.info);
                    }
                },
                error : function(){
                    //ajax操作失败
                    alert('ajax请求失败');
                }


            })
        }

    });

</script>
{/block}